#include<bits/stdc++.h>
using namespace std;
int a[100005];
int ans=0;
int n;
void dfs(int dep,int x,int y,int Ans){
    if(dep>n){
        ans=max(ans,Ans);
        return;
    }
    if(a[dep]==a[x]) dfs(dep+1,dep,y,Ans+a[x]);
    else dfs(dep+1,dep,y,Ans);
    if(a[dep]==a[y]) dfs(dep+1,x,dep,Ans+a[y]);
    else dfs(dep+1,x,dep,Ans);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1; i<=n; i++){
            scanf("%d",&a[i]);
        }
        ans=0;
        dfs(1,0,0,0);
        cout<<ans<<"\n";
    }
    return 0;
}
